package cn.fourhundredandeighteen.service.impl;/**
 * @description:
 * @author: liuyongqi
 * @time: 2020/12/21
 */

import cn.fourhundredandeighteen.dao.AdminDao;
import cn.fourhundredandeighteen.entity.Admin;
import cn.fourhundredandeighteen.service.AdminService;
import cn.fourhundredandeighteen.utill.MysqlConnect;
import cn.fourhundredandeighteen.view.vo.LoginVO;

public class AdminServiceImpl implements AdminService {
    @Override
    public String loginAdmin(LoginVO loginVO) {
        AdminDao adminDao= MysqlConnect.into().getMapper(AdminDao.class);
        try {
            String s = adminDao.adminLogin(loginVO);
            if (s!=null){
                return s;
            }else {
                return null;
            }
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int upAdminInfo(Admin admin) {
        AdminDao adminDao= MysqlConnect.into().getMapper(AdminDao.class);
        int i = adminDao.updateByPrimaryKeySelective(admin);
        MysqlConnect.destroy();
        if (i>0)
            return i;
        else
            return 0;
    }

    @Override
    public Admin getAdmin(Long id) {
        AdminDao adminDao=MysqlConnect.into().getMapper(AdminDao.class);
       try {
           Admin admin = adminDao.selectByPrimaryKey(id);
           MysqlConnect.destroy();
           if (admin!=null)
               return admin;
           else
               return null;
       }catch (Exception e){
           e.printStackTrace();
           return null;
       }
    }
}
